<?php
/**
* @package YaForms
* @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
* @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
* YaForms! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
* Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
*/

defined( '_VALID_MOS' ) or die( 'Restricted access' );

function showEditFields( $option, $formid, &$items, &$itlists, $afcfg_usebehelper='0', $afcfg_fieldsdefaultlayout=''  ) {

   global $database, $mainframe, $item;

   	$mainframe->addCSS( JPATH_SITE.'/components/com_yaforms/includes/js/cnet/acordeon.css');
   
   $a_typeslist = mosHTML::selectList( $itlists['a_types'], 'type[]', 'class="text_area" size="1"', 'value', 'text' );
   $a_requlist  = mosHTML::selectList( $itlists['a_requ'], 'required[]', 'class="text_area" size="1"', 'value', 'text' );
   $a_validlist = mosHTML::selectList( $itlists['a_valid'], 'validation[]', 'class="text_area" size="1"', 'value', 'text'  );
   $a_ronlylist = mosHTML::selectList( $itlists['a_ronly'], 'readonly[]', 'class="text_area" size="1"', 'value', 'text'  );
   $addFieldx   = mosHTML::selectList( $itlists['addFieldx'], 'addFieldx', 'class="text_area" onChange="extrainputbox(this.form)"', 'value', 'text', 'n' );
   $dolayout = urldecode( $afcfg_fieldsdefaultlayout );
   ?>

<table class="adminlist">
  <thead>
    <tr>
      <th colspan="12" align="left"></th>
    </tr>
    <tr>
      <th align="left" width="50"><?php echo YAF_FORM_ORDER; ?></th>
      <th align="left" width="128"><?php echo YAF_FORM_FIELDNAME;?></th>
      <th align="left" width="90"><?php echo YAF_FORM_FIELDTYPE;?></th>
      <th align="left" width="90"><?php echo YAF_FORM_REQUIRED;?></th>
      <th align="left" width="90"><?php echo YAF_FORM_VALIDE;?></th>
      <th align="left" width="128"><?php echo YAF_FORM_VALUES;?></th>
      <th align="left" width="128"><?php echo YAF_FORM_DEFVALUES;?></th>
      <th align="left" width="128"><?php echo YAF_FORM_LAYOUT;?></th>
      <th align="left" width="90"><?php echo YAF_FORM_READONLY;?></th>
      <th align="left" width="128"><?php echo YAF_FORM_CUSTOMCODE;?></th>
    </tr>
    <tr>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_ORDER);?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_FIELDNAME); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_FIELDTYPE); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_REQUIRED); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_VALIDE); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_VALUES); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_DEFVALUES); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_LAYOUT); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_READONLY); ?></th>
      <th align="left"><?php echo mosToolTip(YAF_HELPER_FIELD_CUSTOMCODE); ?></th>
    </tr>
  </thead>
  <?php
      $i=0;

      if ($formid == ''){

                       $i=1;
                       echo "<tr class=\"row0\">
     <td colspan=\"12\" valign=\"top\"><input type=\"hidden\" name=\"form_id[]\" value=\"".$formid."\" />
                                   <input type=\"hidden\" name=\"item_id[]\" value=\"".$item->item_id."\" />
                                   &nbsp;<b>".YAF_FORM_FIELD." #".$i." </b></td>
   </tr><tr class=\"row0\">
			        <td width=\"100px\" valign=\"top\">
                                   <input type=\"hidden\" name=\"form_id[]\" value=\"".$formid."\" />
                                   <input type=\"hidden\" name=\"item_id[]\" value=\"\" />
                                   &nbsp;".YAF_FORM_FIELD."_".$i.":
                                </td>
                                <td align=\"center\" valign=\"top\">
                                   <input class=\"text_area\" type=\"text\" name=\"item_ordering[]\" maxlength=\"4\" align=\"center\" style=\"width:25px;text-align:center;\" value=\"\"/>
                                </td>
				<td width=\"128px\" valign=\"top\">
                                   <input class=\"text_area\" type=\"text\" size=\"20\" name=\"name[]\" value=\"\" />
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   echo $a_typeslist."
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   echo $a_requlist."
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   echo $a_validlist."
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                <textarea class=\"text_area\" type=\"text\" cols=\"15\" rows=\"3\" name=\"values[]\" /></textarea>
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                <textarea class=\"text_area\" type=\"text\" cols=\"15\" rows=\"3\" name=\"default_values[]\" /></textarea>
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                <textarea class=\"text_area\" type=\"text\" cols=\"30\" rows=\"3\" name=\"layout[]\" />".$dolayout."</textarea>
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   echo $a_ronlylist."
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                   <input class=\"text_area\" type=\"text\" name=\"customcode[]\" value=\"\"/>
                                </td>
                                
                                </tr>";

			 } else {

			   foreach ($items as $item) {
                           $i++;
                           $item->values = str_replace("<","&lt;",$item->values);
	                   $item->values = str_replace(">","&gt;",$item->values);
                           $item->default_values = str_replace("<","&lt;",$item->default_values);
	                   $item->default_values = str_replace(">","&gt;",$item->default_values);
	                   $item->layout = str_replace("<","&lt;",$item->layout);
                           $item->layout = str_replace(">","&gt;",$item->layout);
					 if ($i > 1){
                                   $del_img =  "<a href=\"javascript:void(0);\" onClick=\"window.location='index2.php?option=com_yaforms&task=delrow&id=".$formid."&itemdel=".$item->item_id."'\" title=\"".YAF_FORM_ITEMDEL."\">
                                         <img src=\"".JPATH_SITE."/administrator/components/com_yaforms/images/delete.png\" width=\"16\" height=\"16\" border=\"0\" alt=\"".YAF_FORM_ITEMDEL."\"  />
				         </a>";
                                }else{
								$del_img = '';
								}
	 
                           echo "<tr class=\"row0\">
     <td colspan=\"12\" valign=\"top\"><input type=\"hidden\" name=\"form_id[]\" value=\"".$formid."\" />
                                   <input type=\"hidden\" name=\"item_id[]\" value=\"".$item->item_id."\" />
                                   &nbsp;<b>".YAF_FORM_FIELD." #".$i." </b>".$del_img."</td>
   </tr><tr class=\"row0\">
			       
                                <td align=\"center\" valign=\"top\">
                                   <input class=\"text_area\" type=\"text\" name=\"item_ordering[]\" maxlength=\"4\" align=\"center\" style=\"width:25px;text-align:center;\" value=\"".$item->item_ordering."\"/>
                                </td>
				<td width=\"128px\" valign=\"top\">
                                   <input class=\"text_area\" type=\"text\" size=\"20\" name=\"name[]\" value=\"".$item->name."\" />
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   $a_typeslistf = mosHTML::selectList( $itlists['a_types'], 'type[]', 'class="text_area" size="1"', 'value', 'text', $item->type );
                                   echo $a_typeslistf."
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   $a_requlistf = mosHTML::selectList( $itlists['a_requ'], 'required[]', 'class="text_area" size="1"', 'value', 'text', $item->required );
                                   echo $a_requlistf."
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   $a_validlistf = mosHTML::selectList( $itlists['a_valid'], 'validation[]', 'class="text_area" size="1"', 'value', 'text', $item->validation );
                                   echo $a_validlistf."
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                   <textarea class=\"text_area\" type=\"text\" cols=\"10\" rows=\"3\" name=\"values[]\" />".$item->values."</textarea>
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                   <textarea class=\"text_area\" type=\"text\" cols=\"10\" rows=\"3\" name=\"default_values[]\" />".$item->default_values."</textarea>
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                   <textarea class=\"text_area\" type=\"text\" cols=\"15\" rows=\"3\" name=\"layout[]\" />".($item->layout ? $item->layout : $dolayout)."</textarea>
                                </td>
                                <td width=\"90px\" valign=\"top\">";
                                   $a_ronlylistf = mosHTML::selectList( $itlists['a_ronly'], 'readonly[]', 'class="text_area" size="1"', 'value', 'text', $item->readonly );
                                   echo $a_ronlylistf."
                                </td>
                                <td width=\"128px\" valign=\"top\">
                                   <input class=\"text_area\" type=\"text\" name=\"customcode[]\" value=\"".$item->customcode."\"/>
                                </td>
                                </tr>";
                           }
                         }

      $a_typeslist  = eregi_replace( 'ze="1">', 'ze="1">\\', $a_typeslist );
      $a_requlist   = eregi_replace( 'ze="1">', 'ze="1">\\', $a_requlist );
      $a_validlist  = eregi_replace( 'ze="1">', 'ze="1">\\', $a_validlist );
      $a_ronlylist  = eregi_replace( 'ze="1">', 'ze="1">\\', $a_ronlylist );
      $a_typeslist  = eregi_replace( 'n>', 'n>\\', $a_typeslist );
      $a_requlist   = eregi_replace( 'n>', 'n>\\', $a_requlist );
      $a_validlist  = eregi_replace( 'n>', 'n>\\', $a_validlist );
      $a_ronlylist  = eregi_replace( 'n>', 'n>\\', $a_ronlylist );
      $a_typeslist  = eregi_replace( 'ct>', 'ct>\\', $a_typeslist );
      $a_requlist   = eregi_replace( 'ct>', 'ct>\\', $a_requlist );
      $a_validlist  = eregi_replace( 'ct>', 'ct>\\', $a_validlist );
      $a_ronlylist  = eregi_replace( 'ct>', 'ct>\\', $a_ronlylist );

      $dolayout     = base64_encode( $dolayout );
      
      echo '<script type="text/javascript" src="'.JPATH_SITE.'/components/com_yaforms/includes/js/base64/webtoolkit.base64.js"></script>';
                                echo "<script type=\"text/javascript\">

                                     function extrainputbox(form) {

                                     var b64layout = '".$dolayout."';
                                     var getlayout = Base64.decode(b64layout);
                                     var einputs1 = '<table class=\"adminlist\"><tr class=\"row0\">\
     <td colspan=\"12\" valign=\"top\"><input type=\"hidden\" name=\"form_id[]\" value=\"".$formid."\" /><input type=\"hidden\" name=\"item_id[]\" value=\"\" /><b>".YAF_FORM_FIELD."&nbsp;#'; var einputs2 = ':</b>&nbsp;<font color=\"#FF0000\" size=\"2\">".YAF_WARNADDFILD."</font></td></tr>\
					 <tr class=\"row0\"><td align=\"center\" width=\"50px\" valign=\"top\">&nbsp;<input class=\"text_area\" type=\"text\" name=\"item_ordering[]\" maxlength=\"4\" style=\"width:25px;text-align:center;\" value=\"\"/>&nbsp;</td>\
                                                     <td width=\"128px\" valign=\"top\"><input class=\"text_area\" type=\"text\" size=\"20\" name=\"name[]\" value=\"\" /></td>\
                                                     <td width=\"90px\" valign=\"top\">\\".$a_typeslist."</td>\
                                                     <td width=\"90px\" valign=\"top\">\\".$a_requlist."</td>\
                                                     <td width=\"90px\" valign=\"top\">\\".$a_validlist."</td>\
                                                     <td width=\"128px\" valign=\"top\"><textarea class=\"text_area\" type=\"text\" cols=\"10\" rows=\"3\" name=\"values[]\" /></textarea></td>\
                                                     <td width=\"128px\" valign=\"top\"><textarea class=\"text_area\" type=\"text\" cols=\"10\" rows=\"3\" name=\"default_values[]\" /></textarea></td>\
                                                     <td width=\"128px\" valign=\"top\"><textarea class=\"text_area\" type=\"text\" cols=\"15\" rows=\"3\" name=\"layout[]\" />'+getlayout+'</textarea></td>\
                                                     <td width=\"90px\" valign=\"top\">\\".$a_ronlylist."</td>\
                                                     <td width=\"128px\" valign=\"top\"><input class=\"text_area\" type=\"text\" name=\"customcode[]\" value=\"\"/></td>\
                                                     </tr></table>';

                                     var numObj = parseInt(form.addFieldx.value);
                                     var html = '';
                                     var container = document.getElementById('divAddField');

                                     if (numObj > 0) {
                                         for(i=1; i<=numObj; i++) {
                                             var n2 = ".$i." - 1 + i;
                                             n2++;
                                             einputs = (einputs1 + n2 + einputs2);
                                             html += (einputs);
                                         }
                                     }

                                     container.innerHTML = html;

                                }

                                </script>
                                     ";
                ?>
</table>
<div id="divAddField" width="100%"></div>
<br />
<input type="hidden" name="id" value="<?php echo $formid; ?>" />
<input type="hidden" name="option" value="<?php echo $option; ?>" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="task" value="" />
</form>
<div class="affields_2">
  <form name="adminForm2" method="" action="">
    <div width="100%" align="right" height="30"> <?php echo YAF_FORM_NEWFIELD.' '.$addFieldx.mosToolTip(YAF_HELPER_FIELD_NEWFIELD);?> </div>
  </form>
</div>
<?php

}

?>
